/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmLogin.java
 *
 * Created on 04.03.2011, 18:08:03
 */
package de.jrk_verwaltung.security.login.view;

import de.jrk_verwaltung.security.login.CLoginController;

/**
 * 
 * @author JRK-FO
 */
public class frmLogin extends javax.swing.JDialog {

    private static final long serialVersionUID = 1L;
    private CLoginController loginController;

    /**
     * Creates new form frmLogin
     */
    public frmLogin(final java.awt.Frame parent, final boolean modal, final CLoginController loginController) {
        super(parent, modal);
        this.setLocationRelativeTo(null);
        this.loginController = loginController;

        initComponents();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed"
    // desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtUser = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JPasswordField();
        cmdLogin = new javax.swing.JButton();
        cmdCancel = new javax.swing.JButton();
        lblHint = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Login JRK Verwaltung");
        setAlwaysOnTop(true);
        setName("frmLogin");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setText("Benutzername");

        txtUser.setToolTipText("Eingabe es Benutzernamen");
        txtUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUserActionPerformed(evt);
            }
        });
        txtUser.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtUserFocusGained(evt);
            }
        });

        jLabel2.setText("Passwort");

        txtPassword.setAction(loginController.getLoginAction());
        txtPassword.setToolTipText("Eingabe des Passworts");
        txtPassword.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                txtPasswordFocusGained(evt);
            }
        });

        cmdLogin.setAction(loginController.getLoginAction());
        cmdLogin.setText("Login");

        cmdCancel.setAction(loginController.getCancelLoginAction());
        cmdCancel.setText("Abbrechen");

        lblHint.setForeground(new java.awt.Color(255, 0, 0));
        lblHint.setLabelFor(this);
        lblHint.setText(" ");
        lblHint.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        lblHint.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(
                                                layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel1).addComponent(jLabel2))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(txtUser).addComponent(txtPassword)))
                                        .addGroup(
                                                layout.createSequentialGroup()
                                                        .addComponent(lblHint, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(
                                                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addComponent(cmdLogin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                                        .addComponent(cmdCancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                                        .addComponent(txtUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
                                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(
                                                layout.createSequentialGroup().addComponent(cmdLogin)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                        .addComponent(cmdCancel)).addComponent(lblHint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtUserActionPerformed(java.awt.event.ActionEvent evt)// GEN-FIRST:event_txtUserActionPerformed
    {// GEN-HEADEREND:event_txtUserActionPerformed
        txtPassword.grabFocus();
    }// GEN-LAST:event_txtUserActionPerformed

    private void txtUserFocusGained(java.awt.event.FocusEvent evt)// GEN-FIRST:event_txtUserFocusGained
    {// GEN-HEADEREND:event_txtUserFocusGained
        txtUser.selectAll();
    }// GEN-LAST:event_txtUserFocusGained

    private void txtPasswordFocusGained(java.awt.event.FocusEvent evt)// GEN-FIRST:event_txtPasswordFocusGained
    {// GEN-HEADEREND:event_txtPasswordFocusGained
        txtPassword.selectAll();
    }// GEN-LAST:event_txtPasswordFocusGained

    private void formWindowClosing(java.awt.event.WindowEvent evt)// GEN-FIRST:event_formWindowClosing
    {// GEN-HEADEREND:event_formWindowClosing
        loginController.cancelLogin();
    }// GEN-LAST:event_formWindowClosing
     // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton cmdCancel;
    private javax.swing.JButton cmdLogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel lblHint;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtUser;

    // End of variables declaration//GEN-END:variables

    public String getUser() {
        return txtUser.getText();
    }

    public char[] getPassword() {
        return txtPassword.getPassword();
    }

    public void closeView() {
        this.dispose();
    }

    public void showLoginFaultHint(String stateText) {
        lblHint.setText(stateText);
    }
}
